{extend name="/fool" /}
{block name="css"}
<link rel="stylesheet" href="/css/admin/order_two.css">
<style>
    #page{
        position: relative;
        display: inline-block;
        left:30%;
        margin-left:-50px;
        padding:50px 0;
    }
    .qrk{
        background: #fff;display:none;
        width: 300px;height:200px;
        border:1px solid #000;
        position: absolute;left:50%;
        margin-left:-150px;top:40%;
        border-radius: 10px;
        z-index: 999;
    }
</style>
{/block}
{block name="menu_content"}
<div class="qrk">
    <div style="text-align: center;line-height: 50px;font-size: 20px;">确认删除</div>
    <div style="text-align: center;margin:10px 0 30px 0;">
        确认删除当前商品，删除后商品将<br>
        无法在小程序中显示
    </div>
    <div>
        <button type="button" class="qx layui-btn" style="float: left;margin-left: 45px;">取消</button>
        <button type="button" class="qr layui-btn" style="float: right;margin-right: 45px;">确认</button>
    </div>
</div>
<div id="one">
    <form class="layui-form" action="" method="post">
        <ul>

            <li>
                <div class="layui-input-inline">
                    <input type="text" name="name" autocomplete="off" class="layui-input" placeholder="分组名称">
                </div>

                <button type="Submit" class="layui-btn">筛选</button>
                <button type="button" class="add layui-btn">添加分组</button>
            </li>
        </ul>
    </form>
</div>
<div>
    <form class="layui-form" action="" method="post">
        <table>
            <tr>
                <th>分组名称</th>
                <th>包含商品</th>
                <th>创建时间</th>
                <th>排序</th>
                <th>是否展示</th>
                <th class="last">操作</th>
            </tr>
            {if isset($list)}
            {foreach $list as $v}
            <tr class="list">
                <td>{$v.name}</td>
                <td>{$v.title}</td>
                <td>{$v.create_time}</td>
                <td>{$v.list}</td>
                <td>
                    {if $v.status == 10}
                    <input sid="{$v.id}" status="{$v.status}" type="checkbox" name="status" class="status" lay-skin="switch" checked>
                    {else}
                    <input sid="{$v.id}" status="{$v.status}" type="checkbox" name="status" class="status" lay-skin="switch">
                    {/if}
                </td>
                <td>
                    <button sid="{$v.id}" type="button" class="viewbu layui-btn">编辑</button>
                    <button sid="{$v.id}" type="button" class="delete layui-btn layui-btn-danger">删除</button>
                </td>
            </tr>
            {/foreach}
            {/if}
        </table>
    </form>
    <div id="page">
        {if isset($list)}
        {$page|raw}
        {/if}
    </div>
</div>
<script>
    //删除
    var id = 0;
    $(".delete").click(function(){
        id = $(this).attr('sid');
        $(".qrk").show();
    })
    $(".qr").click(function(){
        console.log(id);
        $(".qrk").hide();
        $.post("{:url('delete')}",{id},function (date) {
            history.go(0);
        },'json')
    })
    $(".qx").click(function(){
        $(".qrk").hide();
    })
    $(".add").click(function(){
        parent.$(window.parent.document).find("#hd").show();
        parent.$(window.parent.document).find("#groupadd").show();
        parent.$(window.parent.document).find("#table_one_title").show();
        parent.$(window.parent.document).find("#table_one").show();
        parent.$(window.parent.document).find("#groupadd .table").val('aaa');
        parent.$(window.parent.document).find("#groupadd .class").val('1');
    })
    $(document).on("click", ".layui-form-switch", function() {
        var status = $(this).closest('td').find('input').attr('status');
        var id = $(this).closest('td').find('input').attr('sid');
        $.post("{:url('status')}",{
            id,
            status
        },function(data){
            console.log(data)
        },'json');
    })
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#test1'
            ,type: 'month'
            ,range: '至'
            ,format: 'yyyy-MM'
        });
    });
    $(".viewbu").click(function(){
        var id = $(this).attr('sid');
        var url = "{:url('view',['id'=>'1','index'=>'0'])}" + '&view=' + '0' + '&battery_order=' + id;
        console.log(url);
        location.href = url;
    })
    layui.use('laypage', function(){
        var laypage = layui.laypage;
        //执行一个laypage实例
        laypage.render({
            elem: 'page'
            ,count: "{$count}"
            ,curr:"{$curl}"
            ,last:"{$groups}"
            ,limit:"{$limit}"
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            ,jump: function(obj,first){
                console.log(obj)
                if(!first){
                    var url = "{:url('index',['id'=>5,'index'=>0])}" + '&page=' + obj.curr + '&limit=' + obj.limit + '&curr=' + obj.curr;
                    location.href = url;
                }
            }
        });
    });
</script>
{/block}